/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.sesame.domain.Album;
import com.sesame.domain.Ask;
import com.sesame.domain.User;
import com.sesame.service.AlbumService;
import com.sesame.service.UserService;

/**
 * @author voidman
 * 
 */
public class NewAskController extends SimpleFormController {

    private UserService userService;

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    protected ModelAndView onSubmit(HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors)
            throws Exception {

        Ask ask = (Ask) command;
        String title = ask.getTitle();
        String content = ask.getContent();

        userService.newAsk(title, content, request);
        Map model = errors.getModel();

        return new ModelAndView("redirect:askList.html", model);

    }

}